package name.ekr.edu.threads.chatserver.client;

import java.io.IOException;
import java.io.PrintWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import name.ekr.edu.threads.chatserver.Server;

public class WriterClient extends Thread {
	static Logger logger = LoggerFactory.getLogger(WriterClient.class);
	private Server server;
	private PrintWriter consoleWriter;

	public WriterClient(Server server, PrintWriter consoleWriter) {
		this.server = server;
		this.consoleWriter = consoleWriter;
	}

	@Override
	public void run() {
		String serverInput = null;
		do {
			try {
				serverInput = server.getMessage();
				if(serverInput == null) throw new IOException();
				consoleWriter.println(serverInput);
			} catch (IOException e) {
				logger.debug("", e);
				break;
			}				
		} while(!Thread.interrupted());
	}
}
